<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="#" method="post">
    <p>
        <!--      requeird必填字段-->
        <span>银行账号：</span>
        <input type="text" class="inputsgl" required>
        <span>银行名称：</span>
        <input type="text" id="BankName" required>

    </p>
<!--    <button type="button" onclick="check()">提交</button>-->

</form>

<script>
    function show() {
        tipId = window.setInterval("check()", 1000); //每隔1秒调用一次start()方法
    }
    function check(){
        var BA = document.getElementsByClassName("inputsgl")[0].value
        var patt1 = new RegExp(/\s+/g);
        if (patt1.test(BA)){
            // alert("有空格")
        }
        document.getElementsByClassName("inputsgl").value[0] = BA.replace(/\s+/g,"");
    }
    show();
</script>

</body>
</html>